﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;

public partial class DreamProject_Default2 : System.Web.UI.Page
{
    clsDBOperation objDBOp = new clsDBOperation();
    Hashtable hstParameters = new Hashtable();
    DataSet dsadmin = new DataSet();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetCategory();
            GetMovieCovers();
            GetALLMovie();
        }

    }

    private void GetCategory()
    {
        try
        {
            DataSet dssave = new DataSet();
            hstParameters.Clear();
            hstParameters.Add("Action", "Get_Movie_Category");
            dssave = (DataSet)objDBOp.GetDataset("sp_User_Movie", CommandType.StoredProcedure, hstParameters);
            if (dssave.Tables.Count > 0 && dssave.Tables[0].Rows.Count > 0)
            {
                grdCategoryName.DataSource = dssave;
                grdCategoryName.DataBind();          

            }
            else
            {
                grdCategoryName.DataSource = null;
                grdCategoryName.DataBind();
            }
        }
        catch (Exception ex)
        {

        }

    }

    private void GetMovieCovers()
    {
        try
        {
            DataSet dssave = new DataSet();
            hstParameters.Clear();
            hstParameters.Add("Action", "Get_Movie_Covers");
            dssave = (DataSet)objDBOp.GetDataset("sp_User_Movie", CommandType.StoredProcedure, hstParameters);
            if (dssave.Tables.Count > 0 && dssave.Tables[0].Rows.Count > 0)
            {

                grdMovies.DataSource = dssave;
                grdMovies.DataBind();

            }
            else
            {
                grdMovies.DataSource = null;
                grdMovies.DataBind();
            }
        }
        catch (Exception ex)
        {

        }

    }


    private void GetALLMovie()
    {
        try
        {
            DataSet dssave = new DataSet();
            hstParameters.Clear();
            hstParameters.Add("Action", "Get_All_Movie");
            dssave = (DataSet)objDBOp.GetDataset("sp_User_Movie", CommandType.StoredProcedure, hstParameters);
            if (dssave.Tables.Count > 0 && dssave.Tables[0].Rows.Count > 0)
            {
                grdDownloadLink.Visible = false;
                grdScreen.Visible = false;
                grdMovie.Visible = false;
                grdAllMovies.Visible = true;
                grdAllMovies.DataSource = dssave;
                grdAllMovies.DataBind();


            }
            else
            {
                grdAllMovies.DataSource = null;
                grdAllMovies.DataBind();
            }
        }
        catch (Exception ex)
        {

        }

    }

    private void GetMovieByCategory( int FK_SubCategoryID)
    {
        try
        {
            DataSet dssave = new DataSet();
            hstParameters.Clear();
            hstParameters.Add("Action", "Get_Movie_ByCategory");
            hstParameters.Add("FK_SubCategoryID", FK_SubCategoryID);
            dssave = (DataSet)objDBOp.GetDataset("sp_User_Movie", CommandType.StoredProcedure, hstParameters);
            if (dssave.Tables.Count > 0 && dssave.Tables[0].Rows.Count > 0)
            {

                grdDownloadLink.Visible = false;
                grdScreen.Visible = false;
                grdMovie.Visible = false;
                grdAllMovies.Visible = true;
                grdAllMovies.DataSource = dssave;
                grdAllMovies.DataBind();


            }
            else
            {
                grdAllMovies.DataSource = null;
                grdAllMovies.DataBind();
            }
        }
        catch (Exception ex)
        {

        }

    }


    private void GetMovieByMovieID(int FK_MovieID)
    {
        try
        {
            DataSet dssave = new DataSet();
            hstParameters.Clear();
            hstParameters.Add("Action", "Get_Movie_ByMovieID");
            hstParameters.Add("FK_MovieID", FK_MovieID);
            dssave = (DataSet)objDBOp.GetDataset("sp_User_Movie", CommandType.StoredProcedure, hstParameters);
            if (dssave.Tables.Count > 0 && dssave.Tables[0].Rows.Count > 0)
            {

                grdDownloadLink.Visible = true;
                grdScreen.Visible = true;
                grdMovie.Visible = true;
                grdMovie.DataSource = dssave.Tables[0];
                grdMovie.DataBind();

                grdScreen.DataSource = dssave.Tables[1];
                grdScreen.DataBind();

                grdDownloadLink.DataSource = dssave.Tables[2];
                grdDownloadLink.DataBind();


            }
            else
            {
                grdMovie.DataSource = null;
                grdMovie.DataBind();
            }
        }
        catch (Exception ex)
        {

        }

    }


    protected void grdCategoryName_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName.Equals("MovieCategory"))
        {
            int FK_SubCategoryID = Convert.ToInt32(e.CommandArgument);

            GetMovieByCategory(FK_SubCategoryID);

        }
    }
    protected void grdMovies_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName.Equals("MovieCover"))
        {
            int FK_MovieID = Convert.ToInt32(e.CommandArgument);

            grdAllMovies.Visible = false;

            GetMovieByMovieID(FK_MovieID);

        }
    }
    protected void grdAllMovies_ItemCommand(object source, DataListCommandEventArgs e)
    {

        if (e.CommandName.Equals("Movie"))
        {
            int FK_MovieID = Convert.ToInt32(e.CommandArgument);

            grdAllMovies.Visible = false;

            GetMovieByMovieID(FK_MovieID);

        }
    }
}
